package org.jwebuilder.xom;

import nu.xom.Element;
import nu.xom.NodeFactory;
import nu.xom.Nodes;

public class XmlPageTemplateNodeFactory extends NodeFactory
{
	private Nodes empty = new Nodes();

	private static final String JWB_COMMENT = "jwb:comment";

	private static final String JWB_ANNOTATION = "jwb:annotation";

	private static final String xhtmlNamespaceURI = "http://www.w3.org/1999/xhtml";

	public Element startMakingElement(String name, String namespace)
	{
		// 转换所有标准的 HTML 标签名称为小写形式
		if (xhtmlNamespaceURI.equals(namespace))
		{
			name = name.toLowerCase();
		}
		return new Element(name, namespace);
	}

	public Nodes finishMakingElement(Element element)
	{
		if (element.getQualifiedName().equals(JWB_COMMENT)
				|| element.getQualifiedName().equals(JWB_ANNOTATION))
		{
			// 过滤自定义注释 Element
			return empty;
		}
		else
		{
			return new Nodes(element);
		}
	}
}